package com.zhang.spark_1.spark_core.operator.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @title:
 * @author: zhang
 * @date: 2021/12/5 18:51 
 */
object Spark02_RDD_Operator_Transform {

  def main(args: Array[String]): Unit = {
    //获取spark的连接
    val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("operator")
    val sc: SparkContext = new SparkContext(conf)
    //TODO mapPartitions 将待处理的数据以分区为单位发送到计算节点进行处理，这里的处理是指可以进行任意的处理，哪怕是过滤数据

    val rdd: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4))

    val rddMap: RDD[Int] = rdd.mapPartitions(
      iter => {
        println(">>>>>>>>")
        iter.map(_*2)
      }
    )

    rddMap.collect().foreach(println)
    sc.stop()
  }
}
